package com.jimmy.nonweb.ext;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.reactive.function.client.WebClient;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class GitWebClient {

    @Value("${git.api.beijing.url}")
    private String beijingUrl;
    @Value("${git.api.beijing.port}")
    private String beijingPort;
    @Value("${git.api.beijing.token}")
    private String beijingToken;

    @Value("${git.api.chengdu.url}")
    private String chengduUrl;
    @Value("${git.api.chengdu.port}")
    private String chengduPort;
    @Value("${git.api.chengdu.token}")
    private String chengduToken;

    @Bean
    public WebClient beijingGit(WebClient.Builder builder) {
        String beijingBaseURL = "http://" + beijingUrl + ":" + beijingPort + "/api/v4";
        return builder.baseUrl(beijingBaseURL)
                .defaultHeader("PRIVATE-TOKEN", beijingToken)
                .defaultHeader("Accept", "application/json;charset=UTF-8")
                .build();
    }

    @Bean
    public WebClient chengduGit(WebClient.Builder builder) {
        String chengduBaseURL = "http://" + chengduUrl + ":" + chengduPort + "/api/v4";
        return builder.baseUrl(chengduBaseURL)
                .defaultHeader("PRIVATE-TOKEN", chengduToken)
                .defaultHeader("Accept", "application/json;charset=UTF-8")
                .build();
    }
}
